import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import { CommonLayout, SimplyLayout } from '@/views/layout/index'
import GoodsList from '@/views/goods/list'
import GoodsDetail from '@/views/goods/detail'
import Cart from '@/views/cart/index'
import OrderList from '@/views/order/list'
import orderDetail from '@/views/order/detail'
import OrderBuy from '@/views/order/buy'
import OrderChoiceAddress from '@/views/order/choice-address'
import OrderMemberValidate from '@/views/order/validate'
import OrderPayResult from '@/views/order/pay-result'
import AddressList from '@/views/address/list'
import AddressEdit from '@/views/address/edit'
import MemberProfile from '@/views/member/profile'
import MemberAuthorize from '@/views/member/authorize'
import MemberBinding from '@/views/member/binding'

import NoFound from '@/views/other/no-found'

export default new Router({
    routes: [
        {
            path: '/',
            redirect: { name: 'goodsList' }
        },
        {
            path: '',
            component: SimplyLayout,
            children: [
                {
                    name: 'goodsList',
                    path: 'goods/list',
                    component: GoodsList,
                    meta: { title: '商品列表' }
                }
            ]
        },
        {
            path: '/',
            component: CommonLayout,
            children: [
                {
                    name: 'goodsDetail',
                    path: 'goods/details',
                    component: GoodsDetail,
                    meta: { title: '商品详情' }
                },
                {
                    name: 'cart',
                    path: 'cart',
                    component: Cart,
                    meta: { title: '购物车' }
                },
                {
                    name: 'orderList',
                    path: 'order/list',
                    component: OrderList,
                    meta: { title: '我的订单' }
                },
                {
                    name: 'orderDetail',
                    path: 'order/detail',
                    component: orderDetail,
                    meta: { title: '订单详情' }
                },
                {
                    name: 'orderBuy',
                    path: 'order/buy',
                    component: OrderBuy,
                    meta: { title: '填写订单' }
                },
                {
                    name: 'orderMemberValidate',
                    path: 'order/member/validate',
                    component: OrderMemberValidate,
                    meta: { title: '身份验证' }
                },
                {
                    name: 'orderchoiceAddress',
                    path: 'order/address/choice',
                    component: OrderChoiceAddress,
                    meta: { title: '选择收货地址' }
                },
                {
                    name: 'orderPayResult',
                    path: 'order/pay-result',
                    component: OrderPayResult,
                    meta: { title: '支付订单' }
                },
                {
                    name: 'memberProfile',
                    path: 'member',
                    component: MemberProfile,
                    meta: { title: '个人中心' }
                },
                {
                    name: 'addressList',
                    path: 'address',
                    component: AddressList,
                    meta: { title: '收货地址' }
                },
                {
                    name: 'addressEdit',
                    path: 'address/edit',
                    component: AddressEdit,
                    meta: { title: '' },
                    props: (route) => {
                        route.meta.title = route.query.id ? '编辑地址' : '添加地址'
                    }
                }
            ]
        },
        {
            name: 'memberAuthorize',
            path: '/member/authorize',
            component: MemberAuthorize,
            meta: { title: '登录验证' }
        },
        {
            name: 'memberBinding',
            path: '/member/binding',
            component: MemberBinding,
            meta: { title: '客户身份验证' }
        },
        {
            path: '*',
            name: 'noFound',
            component: NoFound,
            meta: { title: '发生错误了~' }
        }
    ],
    scrollBehavior: () => ({ y: 0 })
})